home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 1286 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.4 KB  |  55 lines

  1. Path: news.uoregon.edu!newsadmin
  2. From: Pat O'Connor <pwoc@darkwing.uoregon.edu>
  3. Newsgroups: comp.lang.c++
  4. Subject: Newbie Template question
  5. Date: 10 Jan 1996 06:47:49 GMT
  6. Organization: University of Oregon
  7. Message-ID: <4cvnel$2cd@pith.uoregon.edu>
  8. NNTP-Posting-Host: darkwing.uoregon.edu
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 1.1N (X11; I; SunOS 5.4 sun4m)
  13. X-URL: news:comp.lang.c++
  14.  
  15. I'm getting a linking error when using templates that I just don't understand.
  16. I have a linked-list class set up where I use a template for the data type.
  17. To debug it, I ran the following program:
  18.  
  19. #include <iostream.h>
  20. #include "List.h"
  21.  
  22. template <class T>        
  23. void PrintList(List<T>& L)    
  24. {    for (L.First(); !L; ++L) cout << L() << endl; }
  25.  
  26. main()
  27. {
  28.     List<int> L;
  29.     for (int i=1; i<5; i++) L.Insert(i);
  30.     PrintList(L);
  31.     return 0;
  32. }
  33.  
  34. This program worked fine.  The problem came when I made what I thought was an
  35. innocent change --  I figured that since I was only going to use "integer" 
  36. Lists, there was no need for the template in PrintList.  So, I replaced
  37.     template <class T>
  38.     void PrintList(List<T>& L)
  39. by the single line
  40.     void PrintList(List<int>& L)
  41.  
  42. When I compiled with this change, I started to get errors from the linker
  43. of the form
  44.  
  45. Unresolved:
  46. List<int>::operator!(void)const
  47. List<int>::operator()(void) const
  48. List<int>::operator++(void)
  49.  
  50. Why???????
  51. Thanks.
  52.  
  53. Pat
  54.  
  55.